#!/bin/sh

e2e_test_install() {
  NODE_LABEL_KEY="$(random_string)"
  NODE_LABEL_VALUE="$(random_string)"

  create_or_replace_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE" 1 \
    --set-string "cluster.pods.scheduling.nodeSelector.$NODE_LABEL_KEY=$NODE_LABEL_VALUE"
}

e2e_test() {
  run_test "Trying to delete size-s with cluster running" delete_with_cluster

  run_test "Trying to delete size-s without cluster running" delete_whitout_cluster
}

delete_with_cluster() {
  if ERROR="$(kubectl delete --dry-run=server -n "$CLUSTER_NAMESPACE" sginstanceprofiles.stackgres.io size-s 2>&1)"
  then
    success "Good. It can delete the configuration"
  else
    fail "It should be able to delete the size-s. ERROR ${ERROR}"
  fi
}

delete_whitout_cluster(){
  kubectl get -n "$CLUSTER_NAMESPACE" sgclusters.stackgres.io "$CLUSTER_NAME" -o yaml | kubectl delete -f -

  if ERROR="$(kubectl delete --dry-run=server -n "$CLUSTER_NAMESPACE" sginstanceprofiles.stackgres.io size-s 2>&1)"
  then
    success "Good. It can delete the configuration"
  else
    fail "It should be able to delete the size-s. ERROR ${ERROR}"
  fi
}
